//
//  YSBusinessHeaderView.m
//  Yueshi
//
//  Created by Northwan on 15/8/12.
//  Copyright (c) 2015年 悦食中国. All rights reserved.
//

#import "YSBusinessHeaderView.h"
#define kTitleFont 14


@interface YSBusinessHeaderView()
@property (strong, nonatomic) UIImageView *iconView;
@property (strong, nonatomic) UILabel *titleLabel;
    
@end

@implementation YSBusinessHeaderView

-(instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if(self){
        UIImageView *iconView  = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, SCREENW, HeaderImgHeight)];
        [self addSubview:iconView];
        _iconView = iconView;
        
        UILabel *titleLabel = [[UILabel alloc]initWithFrame:CGRectMake(YSPublicXInset, CGRectGetMaxY(self.iconView.frame)+YSPublicXInset, SCREENW-YSPublicXInset*2, 15)];
        [titleLabel setFont:SYS_FONT(kTitleFont)];
        [titleLabel setNumberOfLines:0];
        [titleLabel setTextColor:HEXColor(@"#333333")];
        [self addSubview:titleLabel];
        _titleLabel = titleLabel;
    }
    return self;
}

-(void)setSupplier:(YSSupplier *)supplier{
    _supplier = supplier;
    [self.iconView setImageURLStr:supplier.bimageUrl];
    CGSize size = [supplier.supplierDesc sizeWithFont:SYS_FONT(kTitleFont) constrainedToSize:CGSizeMake(SCREENW-YSPublicXInset*2, MAXFLOAT)];
    [self.titleLabel setSize:size];
    [self.titleLabel setText:supplier.supplierDesc];
    [self setFrame:CGRectMake(0, 0, SCREENW, CGRectGetMaxY(self.titleLabel.frame)+YSPublicXInset)];
}

-(void)setInfoWithTopImage:(NSString *)topImage topInfo:(NSString *)topInfo{
    
    CGFloat titleY = YSPublicXInset;
    if(!ISBLANK(topImage)){
        [self.iconView setImageURLStr:topImage];
        titleY = CGRectGetMaxY(self.iconView.frame)+YSPublicXInset;
    }else{
        [self.iconView removeFromSuperview];
    }

    CGSize size = [topInfo sizeWithFont:SYS_FONT(kTitleFont) constrainedToSize:CGSizeMake(SCREENW-YSPublicXInset*2, MAXFLOAT)];
    [self.titleLabel setSize:size];
    [self.titleLabel setText:topInfo];
    self.titleLabel.y = titleY;
    
    UIView *spliteView = [[UIView alloc]initWithFrame:CGRectMake(0, CGRectGetMaxY(self.titleLabel.frame)+YSPublicXInset, SCREENW, YSPublicXInset)];
    [spliteView setBackgroundColor:PUBLIC_BG];
    [self addSubview:spliteView];
    
    [self setFrame:CGRectMake(0, 0, SCREENW, CGRectGetMaxY(spliteView.frame))];
}

-(void)setTopInfo:(NSString *)topInfo{
    [self setInfoWithTopImage:nil topInfo:topInfo];
}

@end
